"""这个是中间层，用来为这个网站后续增加功能等预留的"""
from base_category import get_subdir_folders, get_subdir_videos, count_folder,get_duration
import random,os


def Mock_get_folders_videos(folder_path):
    """模拟带附加信息的文件夹和视频数据"""
    # 获取基础数据
    folders = get_subdir_folders(folder_path)
    videos = get_subdir_videos(folder_path)
    
    # 处理视频附加信息
    enhanced_videos = []
    for video in videos:
        enhanced_videos.append({
            "video_name": video,
            "thumbnail": "https://picsum.photos/400/225",               # 固定缩略图
            "views": random.randint(200, 1000),                         # 随机观看量
            "duration": get_duration(os.path.join(folder_path, video))  # 调用获取时长函数
        })
    
    # 处理文件夹附加信息
    enhanced_folders = []
    for folder in folders:
        enhanced_folders.append({
            "folder_name": folder,
            "videoCount": count_folder(os.path.join(folder_path, folder))  # 调用统计函数
        })
        
    return {
        "folders": enhanced_folders,
        "videos": enhanced_videos
    }

def Mock_get_video_list(folder_path):
    """模拟带附加信息的视频列表数据（树状结构）"""
    from base_category import get_folders_videos_tree
    
    # 获取基础树状结构
    tree = get_folders_videos_tree(folder_path)
    
    # 增强树状结构中的数据
    def enhance_tree_node(node):
        # 处理当前节点的视频
        enhanced_videos = []
        for video in node["videos"]:
            enhanced_videos.append({
                "video_name": video,
                "thumbnail": "https://picsum.photos/400/225",  # 固定缩略图
                "views": random.randint(200, 1000),            # 随机观看量
                "duration": get_duration(os.path.join(folder_path, video))  # 调用获取时长函数
            })
        node["videos"] = enhanced_videos
        
        # 处理子文件夹
        for subfolder in node["subfolders"]:
            # 更新子文件夹信息
            subfolder["videoCount"] = len(subfolder["videos"])
            # 递归处理子文件夹
            enhance_tree_node(subfolder)
            
    # 增强整个树
    enhance_tree_node(tree)
    
    # 添加总视频数量
    from base_category import count_videos_in_tree
    tree["total_videos"] = count_videos_in_tree(tree)
    
    return tree

def Mock_get_all_video_list(folder_path):
    """模拟带附加信息的视频列表数据（树状结构）"""

    from base_category import extractFolderStructure
    folder_structure = extractFolderStructure(folder_path)
        
    videos = get_subdir_videos(folder_path)
    
    # 处理视频附加信息
    enhanced_videos = []
    for video in videos:
        enhanced_videos.append({
            "video_name": video,
            "thumbnail": "https://picsum.photos/400/225",               # 固定缩略图
            "views": random.randint(200, 1000),                         # 随机观看量
            "duration": get_duration(os.path.join(folder_path, video))  # 调用获取时长函数
        })
    
    # 处理文件夹附加信息
    enhanced_folders = []
    for folder_info in folder_structure:
        # 获取父级目录名称
        parent_folder = folder_info["folder_name"]
        
        # 遍历子文件夹
        for subfolder in folder_info["subfolders"]:
            # 拼接完整路径：父目录/子目录
            full_path = os.path.join(folder_path, parent_folder, subfolder)
            
            # 创建增强结构
            enhanced_folders.append({
                "folder_name": subfolder,  # 使用子文件夹名称
                "parent_folder": parent_folder,  # 新增父目录字段
                "videoCount": count_folder(full_path)  # 统计完整路径
            })
        
    return {
        "folders": enhanced_folders,
        "videos": enhanced_videos
    }


if __name__ == "__main__":
    print(Mock_get_folders_videos("./movies/gtx"))
    